// 创建数组的两种方式

const arr = [1, 23, 2, 2, 1, 3, 6, 8, 44, 2, 8]
const arr1 = new Array(1, 2, 3)
console.log(arr);
console.log(arr1);

console.log(arr instanceof Array);
console.log(Array.isArray(arr));

console.log(arr.indexOf(2));
console.log(arr.lastIndexOf(2));

function getSingleArray(arr) {
  let arr1 = []
  for (let item of arr) {
    if (arr1.indexOf(item) === -1) {
      arr1.push(item)
    }
  }
  return arr1
}

console.log(getSingleArray([1, 2, 2, 3, 3, 4, 4]));
console.log([1, 2, 3, 4].toString());
console.log([1, 2, 6, 4].join('-'));

const arr2 = [1, 2, 3]
const arr3 = [4, 5, 6]
console.log(arr1.concat(arr3));
const arr4 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(arr4.slice(1, 3));

const str1 = 'andy'
console.log(str1.length);
const num1 = new Number(123456)
console.log(num1.length);
const str6 = 'hello world'
str6.replace('o', '3')
console.log(str6);


const str2 = 'hello world'
console.log(str2.indexOf('o'));
console.log(str2.lastIndexOf('o'));

// 查找字符串"abcoefoxyozzopp"中所有o出现的位置以及次数
console.log('---');
const str3 = 'abcoefoxyozzopp'
for (let i = 0; i < str3.length; i++) {
  if (str3[i] === 'o') {
    console.log(i);
  }
}



console.log(str3.charAt(0));
console.log(str3[0]);
console.log(str3.charCodeAt(0));


// 判断一个字符串 'abcoefoxyozzopp' 中出现次数最多的字符，并统计其次数。
const str4 = 'abcoefoxyozzopp'
const obj5 = {}
for (let i = 0; i < str4.length; i++) {
  if (obj5.hasOwnProperty(str4[i])) {
    obj5[str4[i]]++
  } else {
    obj5[str4[i]] = 1
  }
}

console.log(obj5);
console.log('hello'.concat('world'));
console.log('hello world'.substr(1, 3));
console.log('hello world'.slice(1, 3));
console.log('hello world'.substring(1, 3));

const str7 = 'hello world'
console.log(str7.replace(/o/g, '3'));
console.log(str7.split('o'));